-- Copyright (c) 2024 Huawei Technologies Co., Ltd.
-- openUBMC is licensed under Mulan PSL v2.
-- You can use this software according to the terms and conditions of the Mulan PSL v2.
-- You may obtain a copy of Mulan PSL v2 at:
--          http://license.coscl.org.cn/MulanPSL2
-- THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
-- EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
-- MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
-- See the Mulan PSL v2 for more details.
local validate = require 'mc.validate'
local utils = require 'mc.utils'
local mdb = require 'mc.mdb'

local TrustedComponent = {}

---@class TrustedComponent.TargetComponent
---@field TargetComponent string
local TTargetComponent = {}
TTargetComponent.__index = TTargetComponent
TTargetComponent.group = {}

local function TTargetComponent_from_obj(obj)
    return setmetatable(obj, TTargetComponent)
end

function TTargetComponent.new(TargetComponent)
    return TTargetComponent_from_obj({TargetComponent = TargetComponent})
end
---@param obj TrustedComponent.TargetComponent
function TTargetComponent:init_from_obj(obj)
    self.TargetComponent = obj.TargetComponent
end

function TTargetComponent:remove_error_props(errs, obj)
    utils.remove_obj_error_property(obj, errs, TTargetComponent.group)
end

TTargetComponent.from_obj = TTargetComponent_from_obj

TTargetComponent.proto_property = {'TargetComponent'}

TTargetComponent.default = {''}

TTargetComponent.struct = {{name = 'TargetComponent', is_array = false, struct = nil}}

function TTargetComponent:validate(prefix, errs, need_convert)
    prefix = prefix or ''

    validate.Optional(prefix .. 'TargetComponent', self.TargetComponent, 'string', true, errs, need_convert)

    TTargetComponent:remove_error_props(errs, self)
    validate.CheckUnknowProperty(self, TTargetComponent.proto_property, errs, need_convert)
    return self
end

function TTargetComponent:unpack(_)
    return self.TargetComponent
end

TrustedComponent.TargetComponent = TTargetComponent

---@class TrustedComponent.Type
---@field Type string
local TType = {}
TType.__index = TType
TType.group = {}

local function TType_from_obj(obj)
    return setmetatable(obj, TType)
end

function TType.new(Type)
    return TType_from_obj({Type = Type})
end
---@param obj TrustedComponent.Type
function TType:init_from_obj(obj)
    self.Type = obj.Type
end

function TType:remove_error_props(errs, obj)
    utils.remove_obj_error_property(obj, errs, TType.group)
end

TType.from_obj = TType_from_obj

TType.proto_property = {'Type'}

TType.default = {''}

TType.struct = {{name = 'Type', is_array = false, struct = nil}}

function TType:validate(prefix, errs, need_convert)
    prefix = prefix or ''

    validate.Optional(prefix .. 'Type', self.Type, 'string', true, errs, need_convert)

    if self.Type ~= nil then
        validate.Enum(prefix .. 'Type', self.Type, '', {'Discrete', 'Integrated'}, errs, need_convert)
    end

    TType:remove_error_props(errs, self)
    validate.CheckUnknowProperty(self, TType.proto_property, errs, need_convert)
    return self
end

function TType:unpack(_)
    return self.Type
end

TrustedComponent.Type = TType

---@class TrustedComponent.Name
---@field Name string
local TName = {}
TName.__index = TName
TName.group = {}

local function TName_from_obj(obj)
    return setmetatable(obj, TName)
end

function TName.new(Name)
    return TName_from_obj({Name = Name})
end
---@param obj TrustedComponent.Name
function TName:init_from_obj(obj)
    self.Name = obj.Name
end

function TName:remove_error_props(errs, obj)
    utils.remove_obj_error_property(obj, errs, TName.group)
end

TName.from_obj = TName_from_obj

TName.proto_property = {'Name'}

TName.default = {''}

TName.struct = {{name = 'Name', is_array = false, struct = nil}}

function TName:validate(prefix, errs, need_convert)
    prefix = prefix or ''

    validate.Optional(prefix .. 'Name', self.Name, 'string', true, errs, need_convert)

    TName:remove_error_props(errs, self)
    validate.CheckUnknowProperty(self, TName.proto_property, errs, need_convert)
    return self
end

function TName:unpack(_)
    return self.Name
end

TrustedComponent.Name = TName

TrustedComponent.interface = mdb.register_interface('bmc.kepler.RoT.TrustedComponent', {
    Name = {'s', {}, true, nil, false},
    Type = {'s', {}, true, nil, false},
    TargetComponent = {'s', {}, true, nil, false}
}, {}, {})

return TrustedComponent
